package com.zlj.accountant.app.weiget;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.zlj.accountant.R;

public class TopBar extends LinearLayout{
	
	private JButton btnLeft,btnRight;
	
	private TextView txtTitle;
	
	private ViewGroup vMiddle;
	
	private Activity root;
	
	public TopBar(Activity context,int view){
		this(context,view,null);
    }
	
	public TopBar(Activity context,int view,String title){
		super(context);
		root = context;
		context.setContentView(R.layout.lyt_widget_topbar);
		ViewGroup viewGroup = (ViewGroup)context.findViewById(R.id.v_middle);
		LayoutInflater factory = LayoutInflater.from(context);
		factory.inflate(view, viewGroup);
		initWidget(title);
    }
	
	private void initWidget(String title){
	    btnLeft = (JButton)root.findViewById(R.id.btn_top_left);
	    btnRight = (JButton)root.findViewById(R.id.btn_top_right);
	    vMiddle = (ViewGroup)root.findViewById(R.id.v_middle);
	    txtTitle = (TextView)root.findViewById(R.id.txt_top_title);
	    if(title==null){
	    	title = getResources().getString(R.string.app_name);
	    }
	    txtTitle.setText(title);
    }

	public Button initLeftButton(int img,OnClickListener l){
		btnLeft.setVisibility(View.VISIBLE);
		btnLeft.setBackgroundResource(img);
		btnLeft.btn.setOnClickListener(l);
		return btnLeft.btn;
	}
	
	public Button initRightButton(int img,OnClickListener l){
		btnRight.setVisibility(View.VISIBLE);
		btnRight.setBackgroundResource(img);
		btnRight.btn.setOnClickListener(l);
		return btnRight.btn;
	}
	
	public void setTitle(String title){
		txtTitle.setText(title);
	}
	
}
